{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.fe775ae2baf6d5d433a6483e80aa0cf4.315360000.1926784115.282335-23581586', 'expires_in': 2592000, 'session_key': '9mzdWECMsyTK3fY3lCH2Y31ER7uPdmvdlYKFveWqEW3nMVC83Mqu7ZImkpoWKKDUoEe8/BdQh6YLbz6R4UMw9qvAMvtY4w==', 'access_token': '24.c0b13b743b10f4fd37d43276158b6e62.2592000.1614016115.282335-23581586', 'scope': 'public vis-classify_dishes vis-classify_car brain_all_scope vis-classify_animal vis-classify_plant brain_object_detect brain_realtime_logo brain_dish_detect brain_car_detect brain_animal_classify brain_plant_classify brain_ingredient brain_advanced_general_classify brain_custom_dish brain_poi_recognize brain_vehicle_detect brain_redwine brain_currency brain_vehicle_damage wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin', 'session_secret': '1381203266250509799f67f0f055b4d0'}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "import requests \n",
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=UhYepBFHfppYS4GRDrorGwM6&client_secret=BGYqUuPEXkaZtB9NGTvXnSMn60z4m5ma'\n",
    "response = requests.get(host)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'log_id': 4686818624777827352,\n",
       " 'location_result': {'width': 326.7148132324219,\n",
       "  'top': 112.8083724975586,\n",
       "  'height': 182.4905395507812,\n",
       "  'left': 110.1487350463867},\n",
       " 'result': [{'score': 0.9817668199539185,\n",
       "   'name': '法拉利LaFerrari',\n",
       "   'year': '2014-2017'},\n",
       "  {'score': 0.004639130085706711, 'name': '法拉利458', 'year': '2010-2014'},\n",
       "  {'score': 0.001572166802361608, 'name': '法拉利488', 'year': '2015-2017'},\n",
       "  {'score': 0.001066661439836025,\n",
       "   'name': '法拉利F12berlinetta',\n",
       "   'year': '2013-2016'},\n",
       "  {'score': 0.0003454091784078628, 'name': '长城炫丽', 'year': '2008-2011'}],\n",
       " 'color_result': '红色'}"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "车型识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v1/car\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open(r'C:/css.jpeg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img,\"top_num\":5}\n",
    "access_token = '24.c0b13b743b10f4fd37d43276158b6e62.2592000.1614016115.282335-23581586'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "#if response:\n",
    " #   print (response.json())\n",
    "response.json()   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'log_id': 6632151370304083768,\n",
       " 'vehicle_num': {'motorbike': 0,\n",
       "  'tricycle': 0,\n",
       "  'car': 1,\n",
       "  'carplate': 0,\n",
       "  'truck': 0,\n",
       "  'bus': 0},\n",
       " 'vehicle_info': [{'type': 'car',\n",
       "   'location': {'width': 312, 'top': 105, 'left': 113, 'height': 191},\n",
       "   'probability': 0.9758495688438416}]}"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "车辆检测\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v1/vehicle_detect\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open(r'C:/css.jpeg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token = '24.c0b13b743b10f4fd37d43276158b6e62.2592000.1614016115.282335-23581586'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "#if response:\n",
    "#    print (response.json())\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'refresh_token': '25.47ea45c109f098fef05211eb9396e420.315360000.1926786812.282335-23581601',\n",
       " 'expires_in': 2592000,\n",
       " 'session_key': '9mzdDcP+KP3xz+lIHfLpJPjcTKilTCjge3bNIU09Jy+UjoaR/5pfxpbo+Edre/dE07BMAYkTSk0moujJFl2aYBLcdQ9pbA==',\n",
       " 'access_token': '24.651d792aba446544042d65e462e2ca56.2592000.1614018812.282335-23581601',\n",
       " 'scope': 'public vis-ocr_ocr brain_ocr_scope brain_ocr_general brain_ocr_general_basic vis-ocr_business_license brain_ocr_webimage brain_all_scope brain_ocr_idcard brain_ocr_driving_license brain_ocr_vehicle_license vis-ocr_plate_number brain_solution brain_ocr_plate_number brain_ocr_accurate brain_ocr_accurate_basic brain_ocr_receipt brain_ocr_business_license brain_solution_iocr brain_qrcode brain_ocr_handwriting brain_ocr_passport brain_ocr_vat_invoice brain_numbers brain_ocr_business_card brain_ocr_train_ticket brain_ocr_taxi_receipt vis-ocr_household_register vis-ocr_vis-classify_birth_certificate vis-ocr_台湾通行证 vis-ocr_港澳通行证 vis-ocr_机动车购车发票识别 vis-ocr_机动车检验合格证识别 vis-ocr_车辆vin码识别 vis-ocr_定额发票识别 vis-ocr_保单识别 vis-ocr_机打发票识别 vis-ocr_行程单识别 brain_ocr_vin brain_ocr_quota_invoice brain_ocr_birth_certificate brain_ocr_household_register brain_ocr_HK_Macau_pass brain_ocr_taiwan_pass brain_ocr_vehicle_invoice brain_ocr_vehicle_certificate brain_ocr_air_ticket brain_ocr_invoice brain_ocr_insurance_doc brain_formula brain_ocr_facade brain_ocr_meter brain_doc_analysis brain_ocr_webimage_loc wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin',\n",
       " 'session_secret': '0152c383e46182bb516b8824d9c0ceed'}"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "import requests \n",
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=N785zGYdsEP4cqBqp6gOp7R1&client_secret=HoLwUgouXiwcZh14tgSVg05szSvkcvU7'\n",
    "response = requests.get(host)\n",
    "#if response:\n",
    "#    print(response.json())\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'words_result': {'number': '豫U88888',\n",
       "  'vertexes_location': [{'x': 182, 'y': 173},\n",
       "   {'x': 319, 'y': 173},\n",
       "   {'x': 319, 'y': 212},\n",
       "   {'x': 181, 'y': 212}],\n",
       "  'color': 'blue',\n",
       "  'probability': [0.9999356269836426,\n",
       "   0.999976396560669,\n",
       "   0.9999842643737793,\n",
       "   0.9999700784683228,\n",
       "   0.9999692440032959,\n",
       "   0.9999771118164062,\n",
       "   0.999954342842102]},\n",
       " 'log_id': 1353048419739893760}"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "车牌识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/ocr/v1/license_plate\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open(r'C:/che.jpeg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token = '24.09406e17abbee9af9cf0c35dcfbc4ce9.2592000.1614018461.282335-23581601'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "#if response:\n",
    "#    print (response.json())\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
